<?php
class MKT_Facebook_Wraper extends MKT_Facebook {
    public function getBatchData($id_socials, $params) {
        $attempt = 0;
        $failed_ids = $id_socials;
        $result = array();
        $log = Zend_Registry::get("log");
        while ($attempt < MAX_ATTEMPTS) {
            try {
                $batch_infos = parent::getBatchData($failed_ids, $params);
                $failed_ids = array();
                foreach ($batch_infos as $id_social => $batch_info) {
                    if (empty($batch_info)) {
                        $failed_ids[] = $id_social;
                    } else {
                        $result[$id_social] = $batch_info;
                    }
                }
                
                if (empty($failed_ids)) {
                    break;
                } else {
                    $attempt++;
                }
            } catch (Exception $e) {
                $log->log("{$e->getMessage()} when get batch data", 0);
                sleep(5);
                $attempt++;
            }
        }
        if ($attempt >= MAX_ATTEMPTS) {
            $log->log("Batch info over $attempt times", 0);
        }
        
        return $result;
    }
}
?>
